package com.pipi.biyesheji.service.impl;

import com.pipi.biyesheji.dao.manager.CategoryManager;
import com.pipi.biyesheji.dao.manager.ProductManager;
import com.pipi.biyesheji.dao.model.CategoryDO;
import com.pipi.biyesheji.dao.model.ProductDO;
import com.pipi.biyesheji.dao.query.CategoryQuery;
import com.pipi.biyesheji.pojo.Category;
import com.pipi.biyesheji.pojo.Product;
import com.pipi.biyesheji.service.ForeService;
import com.pipi.biyesheji.util.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author pipi
 */
@Service
public class ForeServiceImpl implements ForeService {

    @Autowired
    private CategoryManager categoryManager;

    @Autowired
    private ProductManager productManager;

    @Override
    public List<Category> listToThree() {
        CategoryQuery categoryQuery = new CategoryQuery();
        categoryQuery.createCriteria().andIdBetween(1L, 4L);
        List<CategoryDO> categoryDOS = categoryManager.selectByQuery(categoryQuery);
        return categoryDOS.stream().map(categoryDO -> BeanUtils.createCloneBean(categoryDO, Category.class)).collect(Collectors.toList());
    }

    @Override
    public List<Product> getFivePro() {
        List<ProductDO> productDOS = productManager.randFive();
        return productDOS.stream().map(productDO -> BeanUtils.createCloneBean(productDO, Product.class)).collect(Collectors.toList());
    }


}
